package com.iflytek.ssm.studentmanage.controller;


import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iflytek.ssm.studentmanage.entity.Student;
import com.iflytek.ssm.studentmanage.service.StudentsService;

@Controller
@RequestMapping("/student")
public class StudentController {

	private static final Logger log = LoggerFactory.getLogger(StudentController.class);

	@Autowired
	private StudentsService studentService;


	/**
	 * 获取学生对象
	 * 
	 * @GetMapping和@PostMapping等注解是在spring 4.3之后才有的
	 * produces属性：不但可以设置返回值类型还可以设定返回值的字符编码；例如application/json, text/html;
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/{id}")
	@ResponseBody
	public Object getById(@PathVariable("id") Integer id) {
		if (null == id) {
			return "id不能为null";
		}
		Date date = new Date();
		date.setYear(2022);

		Student stu = studentService.getById(id);
		if (null == stu) {
			return "查询不到该学生，id=" + id;
		}
		return stu;
	}

}
